//
//  CustomNSString.m
//  UM_Client2.1_shenghuo
//
//  Created by feng lu on 11-5-24.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "CustomNSString.h"


@implementation NSString (NSStringCategory)

+(NSString*)md5:(NSString*)str
{
    CC_MD5_CTX md5;
    
    CC_MD5_Init(&md5);
    NSLog(@"%@", str);
    
    NSData* fileData = [str dataUsingEncoding:NSUTF8StringEncoding];
    CC_MD5_Update(&md5, [fileData bytes], [fileData length]);
    //const char * fileData = [str UTF8String];
    //CC_MD5_Update(&md5, fileData, strlen(fileData));
    
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5_Final(digest, &md5);
    
    
    NSString* s = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
                   digest[0], digest[1], 
                   digest[2], digest[3],
                   digest[4], digest[5],
                   digest[6], digest[7],
                   digest[8], digest[9],
                   digest[10], digest[11],
                   digest[12], digest[13],
                   digest[14], digest[15]];
    
    NSLog(@"%@", s);
    return s;
}

@end
